// 闭包函数缓存

export function defineStore<T>(fn: () => T) {
  let state: T | null = null
  return () => {
    if (!state) {
      try {
        state = fn()
      }
      catch (error) {
        throw new Error(`Failed to initialize store: ${error.message}`)
      }
    }
    return state
  }
}
